package com.xyht.sca_s.student_manage_system.modules.chargePayment.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.entity.req.SmsWnsChargePaymentRecordReq;
import com.xyht.sca_s.student_manage_system.modules.chargePayment.service.SmsWnsChargePaymentRecordService;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.req.OfflineRefundReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * <p>
 * 缴费记录表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-02-05
 */
@RestController
@SecretBody
@RequestMapping("/chargePayment")
public class SmsWnsChargePaymentRecordController {
    @Resource
    private SmsWnsChargePaymentRecordService smsWnsChargePaymentRecordService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("查询需要缴费的计划")
    @GetMapping("/listPlanNeedPay")
    public ResponseResult listPlanNeedPay(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWnsChargePaymentRecordService.listPlanNeedPay(pageNum, pageSize, userId);
    }

    @ApiOperation("展示已缴费计划")
    @GetMapping("/listPaidPlan")
    public ResponseResult listPaidPlan(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                       HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWnsChargePaymentRecordService.listPaidPlan(pageNum, pageSize, userId);
    }

    @ApiOperation("展示缴费记录")
    @GetMapping("/list")
    public ResponseResult listPaymentRecord(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                            HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWnsChargePaymentRecordService.listPaymentRecord(pageNum, pageSize, userId);
    }

    @ApiOperation("展示本计划收费项")
    @GetMapping("/listCategoryDetail")
    public ResponseResult listPaymentRecord(@RequestParam("planId") String planId,
                                            HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWnsChargePaymentRecordService.listCategoryDetail(planId, userId);
    }

    @ApiOperation("支付")
    @PostMapping("/payment")
    public ResponseResult payment(@RequestBody SmsWnsChargePaymentRecordReq recordReq,
                                  HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsWnsChargePaymentRecordService.payment(recordReq, userId);
    }

    //总的缴费记录
    @ApiOperation("学生缴费记录(0.新生缴费 1.普通缴费 2.招生预支付)")
    @GetMapping("/studentPaymentRecord")
    public ResponseResult getStudentPaymentRecord(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "stuName", required = false) String stuName,
                                                  @RequestParam(value = "type", required = false) Integer type) {
        return smsWnsChargePaymentRecordService.getStudentPaymentRecord(pageNum, pageSize, stuName, type);
    }

    @ApiOperation("普通学生缴费详情")
    @GetMapping("/studentPaymentRecordDetail")
    public ResponseResult getStudentPaymentRecordDetail(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                        @RequestParam(value = "stuName", required = false) String stuName,
                                                        @RequestParam(value = "recordId", required = false) String recordId) {
        return smsWnsChargePaymentRecordService.getStudentPaymentRecordDetail(pageNum, pageSize, stuName, recordId);
    }

    @ApiOperation("缴费流水")
    @GetMapping("/paymentFlow")
    public ResponseResult paymentFlow(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                      @RequestParam(value = "type", required = false) Integer type,
                                      @RequestParam(value = "mode", required = false) Integer mode,
                                      @RequestParam(value = "orgId", required = false) Integer orgId,
                                      @RequestParam(value = "startTime", required = false) Date startTime,
                                      @RequestParam(value = "endTime", required = false) Date endTime,
                                      @RequestParam(value = "searchStr", required = false) String searchStr) {
        return smsWnsChargePaymentRecordService.paymentFlow(pageNum, pageSize, type, mode, orgId, startTime, endTime, searchStr);
    }

    @ApiOperation("移除计划并线下退费")
    @PostMapping("/removePlanOfflineRefund")
    public ResponseResult removePlanOfflineRefund(@RequestBody OfflineRefundReq req) {
        return smsWnsChargePaymentRecordService.removePlanOfflineRefund(req);
    }


    @ApiOperation("缴费流水统计")
    @GetMapping("/paymentFlowStatistics")
    public ResponseResult paymentFlowStatistics(@RequestParam(value = "type", required = false) Integer type, // 统计粒度(0.日 1.周 2.月 3.季度 4.年)
                                                @RequestParam(value = "stepNum", required = false) Integer stepNum) { // 统计步长
        return smsWnsChargePaymentRecordService.paymentFlowStatistics(type, stepNum);
    }


}

